package io.flutter.plugins;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import java.lang.invoke.MethodHandle;
import java.util.HashMap;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

/**
 * @author : wangzw
 * @date : 20-12-4上午11:26
 * @desc :
 */
public class AndroidFlutterPlugin {

    private static final String CHANNEL_NAME = "android_flutter_plugin";

    public static void register(Context context, BinaryMessenger binaryMessenger) {
        new MethodChannel(binaryMessenger, CHANNEL_NAME).setMethodCallHandler(new MethodChannel.MethodCallHandler() {
            @Override
            public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
                switch (methodCall.method) {
                    case "showLongToast":
                        Toast.makeText(context, methodCall.argument(("message")), Toast.LENGTH_LONG).show();
                        result.success(null);
                        break;
                    case "showShortToast":
                        Toast.makeText(context, methodCall.argument(("message")), Toast.LENGTH_SHORT).show();
                        result.success(null);
                        break;
                    case "showToast":
                        // Toast.makeText(context, (String)methodCall.argument("message"), (Integer) methodCall.argument("duration"))
                        result.success(null);
                        break;

                    case "openGps":
                        Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        context.startActivity(intent);
                        result.success(null);
                        break;
                }
            }
        });
    }

}
